package com.lxhdj.common.vo;

import java.io.Serializable;
import java.util.UUID;

public class ResultResponse<T> implements Serializable {

    /**
     * 描述 : id
     */
    private static final long serialVersionUID = 1L;

    /**
     *  成功状态码
     */
    private static final Integer SUCCESS_CODE = 200;
    /**
     * 错误状态码
     */
    private static final Integer FAIL_CODE = 500;
    /**
     * 描述 : 响应ID
     */
    private String id = UUID.randomUUID().toString();

    /**
     * 描述 : 状态码(业务定义)
     */
    private Integer code = ResultResponse.SUCCESS_CODE;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public T getError() {
        return error;
    }

    public void setError(T error) {
        this.error = error;
    }

    /**
     * 描述 : 状态码描述(业务定义)
     */
    private String message = "ok";

    /**
     * 描述 : 结果集(泛型)
     */
    private T result = null;

    /**
     * 描述 : 错误
     */
    private T error = null;

    /**
     * 描述 : 构造函数
     */
    public ResultResponse() {
        super();
    }

    /**
     * 描述 : 构造函数
     *
     * @param result 结果集(泛型)
     */
    public ResultResponse(T result) {
        super();
        this.result = result;
    }


    /**
     * 描述 : 构造函数
     *
     * @param code    状态码(业务定义)
     * @param message 状态码描述(业务定义)
     */
    public ResultResponse(Integer code, String message) {
        super();
        this.code = code;
        this.message = message;
    }

    /**
     * 描述 : 构造函数
     *
     * @param code    状态码(业务定义)
     * @param message 状态码描述(业务定义)
     * @param result  结果集(泛型)
     */
    public ResultResponse(Integer code, String message, T result) {
        super();
        this.code = code;
        this.message = message;
        this.result = result;
    }

    /**
     * 构造成功返回结果-只包含默认提示信息
     *
     * @return
     */
    public static ResultResponse success() {
        ResultResponse<String> restResponse = new ResultResponse<>();
        restResponse.setMessage("OK");
        return restResponse;
    }

    /**
     * 构造成功返回结果-只包含提示信息
     *
     * @param message
     * @return
     */
    public static ResultResponse success(String message) {
        ResultResponse<String> restResponse = new ResultResponse<>();
        restResponse.setMessage(message);
        return restResponse;
    }



    /**
     * 构造成功返回结果-结果
     *
     * @param result
     * @return
     */
    public static <T> ResultResponse success(T result) {
        ResultResponse<T> restResponse = new ResultResponse<>();
        restResponse.setResult(result);
        return restResponse;
    }

    /**
     * 构造成功返回结果-提示信息和结果
     *
     * @param message
     * @param result
     * @return
     */
    public static <T> ResultResponse success(String message, T result) {
        ResultResponse<T> restResponse = new ResultResponse<>();
        restResponse.setMessage(message);
        restResponse.setResult(result);
        return restResponse;
    }

    /**
     * 构造失败返回结果-提示信息
     * @param error
     * @return
     * @param <T>
     */
    public static <T> ResultResponse fail(T error) {
        ResultResponse<T> restResponse = new ResultResponse<>();
        restResponse.setMessage("fail");
        restResponse.setError(error);
        restResponse.setCode(ResultResponse.FAIL_CODE);
        return restResponse;
    }

    /**
     * 构造失败返回结果-提示信息和错误码
     * @param code
     * @param error
     * @return
     * @param <T>
     */
    public static <T> ResultResponse fail(Integer code, T error) {
        ResultResponse<T> restResponse = new ResultResponse<>();
        restResponse.setMessage("fail");
        restResponse.setError(error);
        restResponse.setCode(code);
        return restResponse;
    }


}
